<template>
	<view class="wrap">
		<view class="care-all">
			<view class="cate-section">
				<view class="cate-item" v-for="item in pageList" @tap="goPages(item)" :key='item.pageid'>
					<image v-if="1>=item.pageid" :src="item.urlOne"></image>
					<image v-else :src="item.urlTwo"></image>
					<text>{{item.title}}</text>
				</view>
			</view>
		</view>	
		<view class="tabbar-box">
			<tab-bar :counts="navCounts" :current="navCurrent" @onChange="onNavBarChange"></tab-bar>
		</view>
		<tab-page-one ref='childOne' v-show="navCurrent===0" :pageData="pageData" :changeListData='changeListData'></tab-page-one>
		<tab-page-two ref='childTwo' v-show="navCurrent===1" :pageData="pageData" :changeListData='changeListData'></tab-page-two>
		<tab-page-the ref='childThree' v-show="navCurrent===2" :pageData="pageData" :changeListData='changeListData'></tab-page-the>
		
		<view class="fixed-action-bar">
			<view class="item" @click="handleSave">
				<view class="btn-box">
					<image src="../../../static/images/icon_save.png" mode="widthFix" class="icon"></image>
					<text class="text-edit">立即保存</text>
				</view>
			</view>
			<view class="item" @click="handleNext">
				<view class="btn-box">
					<image src="../../../static/images/icon_next.png" mode="widthFix" class="icon"></image>
					<text class="text-delete">取消返回</text>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import tabBar from '../components/tab-bar.vue';
	import tabPageOne from './components/tab-page-one.vue'
	import tabPageTwo from './components/tab-page-two.vue'
	import tabPageThe from './components/tab-page-the.vue'
	
	export default {
		components:{
			tabBar,
			tabPageOne,
			tabPageTwo,
			tabPageThe,
		},
		data() {
			return {
				pageList:[
					{pageid:1 ,title:"项目入库",urlOne:'/static/images/project_nav_001.png',urlTwo:'/static/images/project_nav_101.png'},
					{pageid:2 ,title:"项目评估",urlOne:'/static/images/project_nav_002.png',urlTwo:'/static/images/project_nav_102.png'},
					{pageid:3 ,title:"项目核查",urlOne:'/static/images/project_nav_003.png',urlTwo:'/static/images/project_nav_103.png'},
					{pageid:4 ,title:"项目再评估",urlOne:'/static/images/project_nav_004.png',urlTwo:'/static/images/project_nav_104.png'},
					{pageid:5 ,title:"商务谈判",urlOne:'/static/images/project_nav_005.png',urlTwo:'/static/images/project_nav_105.png'},
					{pageid:6 ,title:"合同签署",urlOne:'/static/images/project_nav_006.png',urlTwo:'/static/images/project_nav_106.png'},
					{pageid:7 ,title:"公司登记",urlOne:'/static/images/project_nav_007.png',urlTwo:'/static/images/project_nav_107.png'},
					{pageid:8 ,title:"项目供地",urlOne:'/static/images/project_nav_008.png',urlTwo:'/static/images/project_nav_108.png'},
					{pageid:9 ,title:"项目建设",urlOne:'/static/images/project_nav_009.png',urlTwo:'/static/images/project_nav_109.png'},
					{pageid:10 ,title:"投后服务",urlOne:'/static/images/project_nav_010.png',urlTwo:'/static/images/project_nav_110.png'}
				],
				showPage:{show1:false,show2:false,show3:false,show4:false,show5:false,show6:false,show7:false,show8:false,show9:false,show10:false},
				navCounts: [], //订单数量
				navs: [],
				dicData:{},
				navCurrent: 0, //当前tab
				code:'',
				pageData:{},//页面总参数
				renmingData:[],//跟进负责人
				zhutiData:[],//主体名称
				zhongjieData:[],//中介机构名称
				newProject:{},//新建项目后返回的参数
				sendListData:{},
				changeListData:{}
			}
		},
		methods: {
			async addnNewProject(){
				const res = await this.$req({
					url:'bus/proj/toAdd.do',
					method:'GET',
					data:{
						
					}		
				})
				if(res.data.success){
					//跟进负责人
					this.newProject=res.data.attributes
					if(res.data.attributes.zdyDataSource.personDataSourceManage){
						this.renmingData = res.data.attributes.zdyDataSource.personDataSourceManage
					}
					//主体名称
					if(res.data.attributes.zdyDataSource.busInvestorDataSourceManage){
						this.zhutiData=res.data.attributes.zdyDataSource.busInvestorDataSourceManage
					}
					//中介机构名称
					if(res.data.attributes.zdyDataSource.busOrganizationDataSourceManage){
						this.zhongjieData=res.data.attributes.zdyDataSource.busOrganizationDataSource
					}
					const  dicData = JSON.parse(uni.getStorageSync('dicData')) 
					this.changeListData={
						hangyeList:JSON.parse(dicData.inve_field),
						laiyuanList:JSON.parse(dicData.busProjSource),
						suqiuList:JSON.parse(dicData.PROJ_APPEAL),
						laiyuanList:JSON.parse(dicData.busProjSource),
						zhongjieList:this.zhongjieData,
						zhutiList:this.zhutiData,
						renmingList:this.renmingData
					}
				}
			},
			async handleSave(){
				let pageOneData=this.$refs.childOne.sendData
				let pageTwoData=this.$refs.childTwo.sendData
				let pageTwoDataDelete=this.$refs.childTwo.deleteList
				let pageThreeData=this.$refs.childThree.sendData
				let pageThreeListDelete=this.$refs.childThree.listDataDeletet
				let pageThreeWorkDelete=this.$refs.childThree.workDataDeletet
				let projSubjectListData={}
				let teamMemberEditListData={}
				let temaWorkEditListData={}
				this.sendListData.PROJ_STAGE='1'
				this.sendListData.NAME=pageOneData.proName
				this.sendListData.SOURCE=pageOneData.laiyuan_value
				this.sendListData.ORGANIZATION=pageOneData.zhongjie_value
				this.sendListData.PROJ_START_UP=pageOneData.date
				this.sendListData.CREATEWORKGROUP=pageOneData.group
				this.sendListData.INDUSTRY=pageOneData.hangye_value
				this.sendListData.PROJ_APPEAL=pageOneData.suqiu_value
				this.sendListData.REMARK=pageOneData.beizhu
				this.sendListData.PROJ_SURVEY=pageOneData.jianjie
				this.sendListData.EXPECT_INVEST=pageOneData.zongtouzi
				this.sendListData.EXPECT_OUT_START=pageOneData.min_touzi
				this.sendListData.EXPECT_OUT_END=pageOneData.max_touzi
				this.sendListData.EVALUATE=pageOneData.rateData
				if(pageTwoData){
					let projSubjectStr=''
					let pageTwoDataAllList=[]
					pageTwoDataAllList=pageTwoDataDelete.concat(pageTwoData.listData)
					this.sendListData['proj_subject.totalNum']=pageTwoDataAllList.length
					if(pageTwoDataAllList.length){
						for(var i=0;i<pageTwoDataAllList.length;i++){
							projSubjectStr+=`proj_subject.EDITTYPE-${i}:`+pageTwoDataAllList[i].leixing+';'+`proj_subject.DATAKEY-${i}:`+pageTwoDataAllList[i].datakey+';'
							+`proj_subject.PROJ_ID-${i}:`+pageTwoDataAllList[i].proid+';'+`proj_subject.INVESTOR-${i}:`+pageTwoDataAllList[i].zhutiming+';'
							+`proj_subject.INVESTOR_A-${i}:`+pageTwoDataAllList[i].zhucedi+';'+`proj_subject.INVESTOR_B-${i}:`+pageTwoDataAllList[i].lianxiren+';'
							+`proj_subject.INVESTOR_C-${i}:`+pageTwoDataAllList[i].lianxifang+';'
						}
						projSubjectListData=this.changeStr(projSubjectStr)
					}
				}
				this.sendListData.REMARK1=pageTwoData.beizhu
				if(pageThreeData){
					let teamMemberEditStr=''
					let pageThreeDataAllList=[]
					pageThreeDataAllList=pageThreeListDelete.concat(pageThreeData.listData)
					this.sendListData['TeamMember_edit.totalNum']=pageThreeDataAllList.length
					if(pageThreeDataAllList.length){
						for(var i=0;i<pageThreeDataAllList.length;i++){
							teamMemberEditStr+=`TeamMember_edit.EDITTYPE-${i}:`+pageThreeDataAllList[i].leixing+';'+`TeamMember_edit.DATAKEY-${i}:`+pageThreeDataAllList[i].datakey+';'
							+`TeamMember_edit.PROJ_ID-${i}:`+pageThreeDataAllList[i].proid+';'+`TeamMember_edit.MEMBER-${i}:`+pageThreeDataAllList[i].genjinren+';'
							+`TeamMember_edit.LINK_TEL-${i}:`+pageThreeDataAllList[i].lianxifang+';'+`TeamMember_edit.WORK-${i}:`+pageThreeDataAllList[i].zhuyaozhi+';'
						}
						teamMemberEditListData=this.changeStr(teamMemberEditStr)
					}
				}
				if(pageThreeData){
					let temaWorkEditStr=''
					let pageThreeDataAllWork=[]
					pageThreeDataAllWork=pageThreeWorkDelete.concat(pageThreeData.workData)
					this.sendListData['TemaWork_edit.totalNum']=pageThreeDataAllWork.length
					if(pageThreeDataAllWork.length){
						for(var i=0;i<pageThreeDataAllWork.length;i++){
							temaWorkEditStr+=`TemaWork_edit.EDITTYPE-${i}:`+pageThreeDataAllWork[i].leixing+';'+`TemaWork_edit.DATAKEY-${i}:`+pageThreeDataAllWork[i].datakey+';'
							+`TemaWork_edit.PROJ_ID-${i}:`+pageThreeDataAllWork[i].proid+';'+`TemaWork_edit.PLAN_DATE-${i}:`+pageThreeDataAllWork[i].date+';'
							+`TemaWork_edit.CONTENT-${i}:`+pageThreeDataAllWork[i].content+';'
						}
						temaWorkEditListData=this.changeStr(temaWorkEditStr)
					}
				}
				
				this.sendListData.MANAGER=pageThreeData.fuzeren_value
				this.sendListData.TEAM_REMARK=pageThreeData.beizhu
				this.sendListData.isadding=true					//表单标记，true新增表单，false修改表单
				this.sendListData.submit= 1		//是否提交，1为提交
				console.log(this.sendListData,"this.sendListData~~~~~~~")
				const res = await this.$req({
					url:'bus/proj/save.do',
					method:'POST',
					data:{...this.sendListData,...projSubjectListData,...teamMemberEditListData,...temaWorkEditListData}		
				})
				if(res.data.success){
					uni.showToast({
						title:'新建项目成功',
						icon:'none'
					})
					uni.switchTab({
						url: '/pages/projectManerge/projectManerge'
					})
					uni.$emit("refreshDataList", {})
				}else{
					uni.showToast({
						title:res.data.messages[0].content,
						icon:'none'
					})
				}
			},
			handleNext(){
				uni.showToast({
					title:"点击返回"
				})
			},
			changeStr(str){
				let ArryObj={}
				if(str){
					const arryOne=str.split(";")
					arryOne.map(item=>{
						if(item.split(":")[0]){
							ArryObj[item.split(":")[0]]=item.split(":")[1]
						}
						
					})
					for(var i in ArryObj){
						if(ArryObj[i]==="null"){
							ArryObj[i]=null
						}
					}
					return ArryObj
				}
				
			},
			//tab切换
			onNavBarChange(current){
				console.log(current,"~~~~~~~~~")
				if(this.navCurrent === current){
					return;
				}
				this.navCurrent = current;
				this.refreshList();
			},
			goPages(item){
				let goPageUrl=''
				if(item.pageid>1){
					return uni.showToast({
						title:'新建项目，无法进行下一阶段',
						icon:'none'
					})
				}
			},
			
			refreshList(){},
		},
		onLoad(options) {
			console.log(options,"options参数为")
			this.addnNewProject()
			this.goPages(this.pageList[0])
			
		}
	}
</script>

<style lang="scss" scoped>
	.wrap{
		padding-bottom: 60rpx;
	}
	page{
		padding-bottom: 20rpx;
	}

	.fixed-action-bar{
		width: 100%;
		display: flex;
		height: 70rpx;
		align-items: center;
		background: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 999;
		.item{
			width: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
			
		}
		.icon{
			width: 30rpx;
		}
		.btn-box{
			width: 140rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 70rpx;
		}
		.text-edit{
			font-size: 24rpx;
			color: #0099cc;
			line-height: 70rpx;
		}
		.text-delete{
			font-size: 24rpx;
			color: #cc3357;
			line-height: 70rpx;
		}
	}
	
	
	.tabbar-box{
		width: 750rpx;
		height: 70rpx;
		margin-top: 10rpx;
	}
	.care-all{
		height: 230rpx;
		// padding-top: 22rpx;
		padding: 22rpx 34rpx 0 34rpx;
		background: #fff;
		.cate-section {
			width:682rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			flex-wrap:wrap;
			
			.cate-item {
				width: 20%;
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size:26rpx;
				color: #303133;
				margin-bottom: 20rpx;
			}
			image {
				width: 50rpx;
				height: 50rpx;
				margin-bottom: 10rpx;
				// border-radius: 50%;
			}	
		}
	}
</style>
